import { MES_LXK_ApiHost } from '@/utils/Interceptors'

// 定义数据类型
export interface ProductionReport {
  productionId: number
  workOrderId: number
  workOrderNumber: string
  workOrderPlanQuantity: number
  workOrderActualQuantity: number
  workOrderStatus: string
  workOrderRemark: string
  workOrderPlanStartTime: string
  workOrderPlanEndTime: string
  workOrderActualStartTime: string
  workOrderActualEndTime: string
  productId: number
  productNumber: string
  productName: string
  productSpecification: string
  productUnit: string
  workProcessId: number
  workProcessNumber: string
  workProcessName: string
  reportingId: number
  reportingQuantity: number
  taskId: number
  taskPlanStartTime: string
  taskPlanEndTime: string
  taskActualStartTime: string
  taskActualEndTime: string
  taskPlanQuantity: number
  taskActualQuantity: number
  isDelete: boolean
}

export interface ApiResponse {
  code: number
  msg: string
  data: ProductionReport[]
}

export interface SearchParams {
  startTime?: string
  endTime?: string
  workOrderNumber?: string
  productName?: string
  workOrderStatus?: string
}

// 获取所有生产报表数据
export const getAllProductionReports = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/ProductionReport/GetAllProductionReports', { params })
}

// 根据条件搜索生产报表数据
export const searchProductionReports = async (params: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/ProductionReport/GetAllProductionReports', { params })
}

// 导出生产报表数据
export const exportProductionReports = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get('/api/ProductionReport/ExportProductionReports', { 
    params,
    responseType: 'blob',
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, */*'
    }
  })
}
